<!-- D:/project/app/ydz-app-uniapp/static/images/mine -->
<template>
	<view class="pagebody">
		<view class="topbox">
			<view class=" align-center justify-between">
				<view class=" flex-row align-center">
					<image @click="backpage" src="@/static/images/login/leftjt.png" alt=""
						style="width: 48rpx;height: 48rpx;"></image>
				</view>
				<view class="flex-row-center align-center">
					<view class="color303b39 fz40" @click="changenav(1)" :class="isnav==1?'isnav':'nav'">
						收藏
					</view>
					<view class="color303b39 fz40 fwbold ml45 mr45" @click="changenav(2)"
						:class="isnav==2?'isnav':'nav'" style="">
						赞过
					</view>
					<view class="color303b39 fz40 fwbold" @click="changenav(3)" :class="isnav==3?'isnav':'nav'"
						style="">
						评论
					</view>
				</view>
				<view class="">

				</view>
			</view>
		</view>

		<view class="box" v-if="isnav==1">
			<view class="card justify-between" @click="todetail(item)" v-for="(item,index) in list" :key="index">
				<view class="" style="width: 580rpx;">
					<view class="flex-row">
						<img :src="baseUrl+item.invitation.invAvatar"
							style="margin-right: 16rpx;width: 68rpx;height: 68rpx;border-radius: 50%;flex-shrink: 0;">
						<view class="">
							<view class="flex-row align-center ">
								<span class="mr16"
									style="color: #303B39;font-size: 32rpx;font-weight: 800;">{{item.invitation.invName}}</span>
								<span class="fz24" style="color: #7E8987;">{{item.createTime.slice(0,10)}}</span>
							</view>
							<view class="mt25 flex-row">
								<view v-if="item.invitation.attachFiles!=null&&item.invitation.attachFiles.length>0"
									class="imgbox" style="flex-shrink: 0;"
									:style="{ background: 'url(' + item.invitation.attachFiles[0].url + ') no-repeat' }">
								</view>
								<view v-else class="justify-center br16 align-center fz28 fwbold"
									style="color: #A4AFAD; width: 106rpx;height: 106rpx; background: #F0F6F5;">
									暂无
								</view>
								<view class=" ml16 lineclamp2 color303b39 fz32 fwbold" style="line-height: 54rpx;">
									{{item.invitation.title}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class=" align-center justify-center" style="width: 106rpx;">
					<image @click.stop="delsc(item)" src="../../static/images/mine/issc.png"
						style="width: 46rpx;height: 46rpx;" mode=""></image>
				</view>

			</view>
		</view>
		<view class="box" v-if="isnav==2">
			<view class="card" @click="todetail(item)" v-for="(item,index) in likelist" :key="index">
				<!-- 							<view class="flex-row align-center ">
								<span class="mr16" style="color: #303B39;font-size: 32rpx;font-weight: 800;">{{item.invitation.invName}}</span> <span class="fz24" style="color: #7E8987;">{{item.createTime.slice(0,10)}}</span>
							</view> -->
				<view class="mt25 flex-row">
					<view v-if="item.attachFiles!=null&&item.attachFiles.length>0" class="imgbox"
						style="flex-shrink: 0;"
						:style="{ background: 'url(' + item.attachFiles[0].url + ') no-repeat' }">
					</view>
					<view v-else class="justify-center br16 align-center fz28 fwbold"
						style="color: #A4AFAD; width: 106rpx;height: 106rpx; background: #F0F6F5;">
						暂无
					</view>
					<view class="ml16" style="width: 100%;">
						<view class=" lineclamp1 color303b39 fz32 fwbold" style="line-height: 54rpx;">
							{{item.invitation.title}}
						</view>
						<view class="color303b39 fz28">
							你点赞了{{item.replyId?'评论':'帖子'}}
						</view>
						<view v-show="item.replyId"
							style="color: #7E8987;border-left: 1rpx solid #A4AFAD;padding-left: 16rpx;"
							class="fz24 lineclamp1">
							{{item.reply?item.reply.replyContent:''}}
						</view>
						<view class="justify-between flex-row mt10" style="padding-right: 24rpx;">
							<view class="" style="color: #7E8987;">
								{{item.createTime.slice(0,10)}}
							</view>
							<image @click.stop="dellike(item)" src="../../static/images/mine/dellike.png"
								style="width: 32rpx;height: 32rpx;" mode=""></image>

						</view>
					</view>

				</view>
			</view>
		</view>
		
		<view class="box" v-if="isnav==3">
			<view class="card" @click="todetail(item)" v-for="(item,index) in replylist" :key="index">
				<!-- 							<view class="flex-row align-center ">
								<span class="mr16" style="color: #303B39;font-size: 32rpx;font-weight: 800;">{{item.invitation.invName}}</span> <span class="fz24" style="color: #7E8987;">{{item.createTime.slice(0,10)}}</span>
							</view> -->
				<view class="mt25 flex-row">
					<view v-if="item.attachFiles!=null&&item.attachFiles.length>0" class="imgbox"
						style="flex-shrink: 0;"
						:style="{ background: 'url(' + item.attachFiles[0].url + ') no-repeat' }">
					</view>
					<view v-else class="justify-center br16 align-center fz28 fwbold"
						style="color: #A4AFAD; width: 106rpx;height: 106rpx; background: #F0F6F5;">
						暂无
					</view>
					<view class="ml16" style="width: 100%;">
						<view class=" lineclamp1 color303b39 fz32 fwbold" style="line-height: 54rpx;">
							{{item.invitation.title}}
						</view>
						<view class="color303b39 fz28 lineclamp2">
							<span style="color: #576260;">你评论了:</span>{{item.replyContent}}
						</view>
						<view class="justify-between flex-row mt10" style="padding-right: 24rpx;">
							<view class="" style="color: #7E8987;">
								{{item.createTime.slice(0,10)}}
							</view>
							<image @click.stop="delpl(item)" src="../../static/images/mine/dellike.png"
								style="width: 32rpx;height: 32rpx;" mode=""></image>
		
						</view>
					</view>
		
				</view>
			</view>
		</view>
		<u-modal v-model="delshow" :show-cancel-button="true" :confirm-text="'是'" @confirm="delthislike"
			@cancel="delshow=false" :cancel-text="'否'" content="是否取消点赞？"></u-modal>
		<u-toast ref="uToast" />
		<u-modal v-model="delscshow" :show-cancel-button="true" :confirm-text="'是'" @confirm="delthissc"
			@cancel="delscshow=false" :cancel-text="'否'" content="是否取消收藏？"></u-modal>
		<u-toast ref="uToast" />
		<u-modal v-model="delplshow" :show-cancel-button="true" :confirm-text="'是'" @confirm="delthispl"
			@cancel="delplshow=false" :cancel-text="'否'" content="是否删除评论？"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getOwnerinv,
		invlike,
		replylike,
		delReply,
		getDicts,
		invcollectAdd,
		delInvitation,
		getToOtherLike,
		getToOtherReply
	} from '@/api/api.js'
	import config from '@/config'
	import FixedFoot from '../../layouts/fixedfoot.vue';
	export default {
		components: {
			FixedFoot,
		},
		onLoad() {

		},
		data() {
			return {
				baseUrl: config.baseUrl,
				list: [],
				isnav: 1,
				likelist: [],
				delshow: false,
				replylike: false,
				delid: 0,
				invitationid:0,
				delscshow: false,
				replylist:[],
				delplshow:false,
			}
		},
		created() {
			this.getlist()

		},
		mounted() {},


		methods: {
			reset(){
				
			},
			delpl(item){
				this.delid = item.id
				this.delplshow = true
			},
			delthispl(){
				delReply(this.delid).then(res=>{
					this.$refs.uToast.show({
						title: res.msg,
					})
					this.getreplylist()
				})
				
			},
			delsc(item) {
				console.log(item)
				this.delid = item.invitationId
				this.delscshow = true
			},
			delthissc() {
				let data = {
					invitationId: this.delid,
					status: 1
				}
				invcollectAdd(data).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
					})
					this.getlist()
				})
				
			},
			delthislike() {
				if (this.replylike) {
					// !!!!!!!!这里需要帖子id
					let data = {
						invitationId: this.invitationid,
						replyId: this.delid,
						status: 1,
					}
					replylike(data).then(res => {
						this.$refs.uToast.show({
							title: res.msg,
						})
						this.getlikelist()
					})
				} else {
					let data = {
						invitationId: this.invitationid,
						status: 1
					}
					invlike(data).then(res => {
						this.$refs.uToast.show({
							title: res.msg,
						})
						this.getlikelist()
					})
				}
				this.replylike = false

			},
			dellike(item) {
				if (item.replyId) {
					this.replylike = true
					this.delid = item.replyId
				}
				this.invitationid = item.invitation.id
				this.delshow = true

			},
			backpage() {
				uni.navigateBack({
					delta: 1
				});
			},
			getlist() {
				getOwnerinv().then(response => {
					this.list = response.rows
				})

			},
			todetail(item) {
				uni.navigateTo({
					url: '/pages/forum/forumdetail?id=' + item.invitationId
				})
			},
			changenav(index) {
				this.isnav = index
				this.list = []
				if (index == 1) {
					getOwnerinv().then(response => {
						this.list = response.rows
					})
				} else if (index == 2) {
					this.getlikelist()
				}else{
					this.getreplylist()
				}

			},
			getlikelist() {
				getToOtherLike().then(response => {
					const mergedArray = [...response.data.ReplyLikes, ...response.data.invitationLikes].sort((
						a, b) => {
						return new Date(b.createTime) - new Date(a.createTime); // 降序
					});
					this.likelist = mergedArray
				})
			},
			getreplylist(){
				getToOtherReply().then(res=>{
					this.replylist = res.data
					
				})
			}


		},

	}
</script>

<style lang="scss" scoped>
	.pagebody {
		padding-bottom: 136rpx;
		background: #fff;

		.topbox {
			height: 88rpx;
			background: #fff;
			padding: 20rpx 24rpx;

			.isnav {
				font-size: 36rpx;
				font-weight: bold;
				color: #303b39;
			}

			.nav {
				font-weight: 400;
				font-size: 32rpx;
				color: #576260;
			}
		}

		.box {
			padding: 0 24rpx;

			.card {
				width: 100%;
				margin-top: 56rpx;

				.imgbox {
					height: 106rpx;
					width: 106rpx;
					background-size: cover !important;
					border-radius: 16rpx;
					background-position: center !important;
				}
			}
		}

	}
</style>